<!---->
<template>
    <div class="page_edittudi">
        <common-header :title="'土地信息编辑'">
            <span slot="overwrite-left"></span>
        </common-header>
        <div class="btn-save" @click="saveLandTransferInfo()">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info">
                <div class="item-item">
                    <div class="item-item every-block-padding item-inline">
                        <span class="item-itemLabel">流转类型</span>
                        <select class="translateBlock" v-model="info.transfertype" :disabled="id ? true: false"
                                style="text-align-last: right;;width: 7.2rem;font-size:0.38rem;">
                            <option :value="1">耕地</option>
                            <option :value="2">林地</option>
                        </select>
                    </div>
                </div>
                <div class="item-item"
                     v-if=" (hasGendi === 1 && info.transfertype === 1 ) || (hasLindi === 1 && info.transfertype ===2 )">
                    <x-input title="原有数量(亩)"  type="number" v-model="info.landarea"
                             placeholder="请输入原有数量(亩)">
                    </x-input>
                </div>
                <div class="item-item">
                    <x-input title="流转亩数" type="number" v-model="info.transferarea"
                             placeholder="请输入流转数量(亩)">
                    </x-input>
                </div>
                <div class="item-item">
                    <datetime :min-year="1900" title="流转时间" placeholder="请选择流转时间" v-model="expropriationtime"></datetime>
                </div>

                <div class="item-item">
                    <x-input title="流转金额(元/年)" type="number" v-model="info.transferoffset"
                             placeholder="请输入流转金额(元/年)">
                    </x-input>
                </div>

                <div class="item-item every-block-padding item-inline">
                    <span class="item-itemLabel">流转去向</span>
                    <select class="translateBlock" v-model="info.landdirection"
                            style="text-align-last: right;width: 7.2rem;font-size:0.38rem;">
                        <option :value="1">专业合作社</option>
                        <option :value="2">公司</option>
                        <option :value="3">个人</option>
                        <option :value="4">其他</option>
                    </select>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'
    import {XInput, Selector, Datetime} from 'vux'
    import {checkNumber} from '../../utils/validate'

    export default {
        name: "edittudi",
        components: {
            XInput, Selector, Datetime
        },
        data() {
            return {
                id: this.$route.query.id,
                isShowNumber: this.$route.query.isShowNumber,
                expropriationtime: this.$route.query.expropriationtime,
                hasGendi: Number(this.$route.query.hasGendi),
                hasLindi: Number(this.$route.query.hasLindi),
                info: {
                    familyid: this.$route.query.familyid,
                    villagecode: this.$route.query.villagecode,
                    transfertype: Number(this.$route.query.transfertype) === 2 ? 2 : 1,
                    landarea: this.$route.query.landarea ? this.$route.query.landarea : '',
                    transferarea: this.$route.query.transferarea,
                    expropriationtime: '',
                    transferoffset: this.$route.query.transferoffset,
                    landdirection: Number(this.$route.query.landdirection) ? Number(this.$route.query.landdirection) : 1,
                },
            }
        },

        created() {

        },
        watch: {},
        methods: {
            // 保存土地信息
            saveLandTransferInfo() {
                if ((this.hasGendi === 1 && this.info.transfertype === 1) || (this.hasLindi === 1 &&
                    this.info.transfertype === 2) || this.id) {
                    if (!this.info.landarea) {
                        this.$vux.toast.show({
                            text: '请输入正确的原有亩数（数字类型且最多保留两位小数）',
                            type: 'text',
                            position: 'middle',
                        })
                        return;
                    }
                    if(!checkNumber(this.info.landarea,'原有亩数')){
                        return
                    }
                }

                let param = {
                    transferarea: '请输入正确的流转亩数（数字类型且最多保留两位小数）',
                    expropriationtime: '请选择流转时间',
                    transferoffset: '请输入正确的流转金额（数字类型且最多保留两位小数）',
                    landdirection: '请选择流转去向',
                }

                for (let i in param) {

                    if (i === 'expropriationtime') {
                        if (!this.expropriationtime) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    } else {
                        if (!this.info[i]) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    }

                }

                if(!checkNumber(this.info.transferarea,'流转亩数')){
                    return
                }
                if(!checkNumber(this.info.transferoffset,'流转金额')){
                    return
                }



                this.info.expropriationtime = this.expropriationtime + ' ' + '00:00:00';
                if (this.id) {
                    this.info = Object.assign(this.info, {id: this.id})
                }
                if (this.info.transfertype === 1) {

                }
                let _param = this.$tools.invokeUAF('resident/saveLandTransferInfo', this.info)
                resident.saveLandTransferInfo(_param).then(res => {
                    // this.info.expropriationtime = this.info.expropriationtime.slice(0, 10)
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/css">
    .page_edittudi {
    }

</style>
